package com.designpatterns.factorypattern.abstractfactory;

/**
 * 公共的工厂，根据一定的规则去选择工厂来生产所需产品
 * 此处以产品编号为1开头的使用ProductFactory1来生产...
 */
public class ProductFactory implements IProductFactory {
    @Override
    public IProduct createProduct(String productNo) {
        char start = productNo.charAt(0);
        IProductFactory factory = null;
        if (start == '1') {
            factory = new ProductFactory1();
        } else if (start == '2') {
            factory = new ProductFactory2();
        } else if (start == '3') {
            factory = new ProductFactory3();
        }
        if (factory != null) {
            return factory.createProduct(productNo);
        }
        return null;
    }
}
